<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="inboundColumns"
      :dataSource="inboundList"
      :customRow="handleRowClick"
    >
    </a-table>
    <a-descriptions
      v-if="vehicleInspectionResult.dataSource.length > 0"
      title="车辆检查项目"
      bordered
      :column="2"
      class="vehicle-inspection-result"
    >
      <a-descriptions-item
        v-for="(item, index) in vehicleInspectionResult.dataSource"
        :key="index"
        :label="`${index + 1}.${item.itemName}`"
      >
        <div>{{ item.resultValue }}</div>
      </a-descriptions-item>
    </a-descriptions>
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'

export default {
  name: 'inbound',
  data() {
    return {
      description: '材料入库信息',
      inboundList: [],
      inboundColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 40,
          align: 'center',
          fixed: 'left',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '入库类型',
          align: 'center',
          dataIndex: 'entryType_dictText',
          fixed: 'left',
        },
        {
          title: '单据号',
          align: 'center',
          dataIndex: 'documentNumber',
          fixed: 'left',
        },
        {
          title: '入库单号',
          align: 'center',
          dataIndex: 'entryNumber',
        },
        {
          title: '客户物料编码',
          align: 'center',
          dataIndex: 'customerMaterialCode',
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'materialCode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'specificationModel',
        },
        {
          title: '物料描述',
          align: 'center',
          dataIndex: 'materialDesc',
        },
        {
          title: '主计量单位',
          align: 'center',
          dataIndex: 'unit_dictText',
        },
        {
          title: '主数量',
          align: 'center',
          dataIndex: 'quantity',
        },
        {
          title: '辅计量单位',
          align: 'center',
          dataIndex: 'secondaryUnit_dictText',
        },
        {
          title: '辅数量',
          align: 'center',
          dataIndex: 'secondaryQuantity',
        },
        {
          title: '生产日期',
          align: 'center',
          dataIndex: 'productionDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '保质期（天）',
          align: 'center',
          dataIndex: 'shelfLife',
        },
        {
          title: '限用日期',
          align: 'center',
          dataIndex: 'expirationDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'productionShop_dictText',
        },
        {
          title: '供应商名称',
          align: 'center',
          dataIndex: 'supplierName',
        },
        {
          title: '客户名称',
          align: 'center',
          dataIndex: 'customerName',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'creator_dictText',
        },
        {
          title: '制单人部门',
          align: 'center',
          dataIndex: 'creatorDeptCode_dictText',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'creationDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '入库数量',
          align: 'center',
          dataIndex: 'storedQuantity',
        },
        {
          title: '批次号',
          align: 'center',
          dataIndex: 'batchNumber',
        },
        {
          title: '物料批号',
          align: 'center',
          dataIndex: 'materialBatchNumber',
        },
        {
          title: '储位',
          align: 'center',
          dataIndex: 'storageLocation_dictText',
        },
        {
          title: '入库日期',
          align: 'center',
          dataIndex: 'entryDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '质检状态',
          align: 'center',
          dataIndex: 'qualityInspectionStatus_dictText',
        },
        {
          title: '宝洁采购订单号',
          align: 'center',
          dataIndex: 'pgPurchaseOrderNumber',
        },
        {
          title: '宝洁供应商编号',
          align: 'center',
          dataIndex: 'pgSupplierCode',
        },
        {
          title: '宝洁供应商',
          align: 'center',
          dataIndex: 'pgSupplierCode_dictText',
        },
        {
          title: '经办人',
          align: 'center',
          dataIndex: 'handler_dictText',
        },
        {
          title: '经办人部门',
          align: 'center',
          dataIndex: 'handlerDeptCode_dictText',
        },
        {
          title: '经办日期',
          align: 'center',
          dataIndex: 'handlingDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
          scopedSlots: { customRender: 'remark' },
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderNumber',
        },
      ],
      vehicleInspectionResult: {
        dataSource: [],
      },
      url: {
        inboundList: '/wms/inventory/pageList',
        vehicle: '/wms/inbound/inbound-record/queryVehicleInspectionResultByMainId',
      },
    }
  },
  methods: {
    loadInboundData(batchNumber, convert) {
      this.inboundList = []
      if (batchNumber) {
        let params = { pageSize: 999, pageNo: 1 }
        if (convert) {
          params.planNumber = batchNumber
        } else {
          params.batchNumber = batchNumber
        }
        getAction(this.url.inboundList, params).then((res) => {
          if (res.success) {
            this.inboundList = res.result.records || res.result || []
          }
        })
      }
    },
    handleRowClick(record, index) {
      if (!record) return {}
      return {
        on: {
          click: (event) => {
            if (record.inboundRecordId) {
              this.vehicleInspection({ id: record.inboundRecordId })
            }
          },
        },
      }
    },
    vehicleInspection(params) {
      getAction(this.url.vehicle, params).then((res) => {
        if (res.success && res.result.length > 0) {
          this.vehicleInspectionResult.dataSource = res.result
        }
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
::v-deep .ant-descriptions-title {
  font-size: 13px !important;
}
::v-deep .ant-descriptions-bordered .ant-descriptions-item-label {
  padding: 6px 20px !important;
}
::v-deep .ant-descriptions-bordered .ant-descriptions-item-content {
  padding: 6px 20px !important;
}
</style>
